local terminal = require "terminal"
--- @class udpApi
--- @field udp userdata
local udpApi = {
  udp = nil
}

function udpApi:create()
  self.udp = net.createUDPSocket()
  self.udp:listen(5000)
  self.udp:on("receive", function(s, data, port, ip)
    --print(string.format("received '%s' from %s:%d", data, ip, port))
--    s:send(port, ip, "echo: " .. data)
    terminal:udpReceiveListener(s, data, port, ip)
  end)
end

function udpApi:close()
  self.udp:close()
end

function udpApi:listen()
  self.udp:listen(5000)
end
return udpApi
